home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / GET_LANG.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  16KB  |  408 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*               This module was written by Vince Perriello                 */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*             BinkleyTerm Language Compiler Raw Input Module               */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #ifdef __TURBOC__
  50. #include <mem.h>
  51. #else
  52. #ifdef _MSC_VER_
  53. #include <memory.h>
  54. #else
  55. #include <string.h>
  56. #endif
  57. #endif
  58.  
  59. #ifdef OS_2
  60. #define OS_IDENT "OS2"
  61. #else
  62. #define OS_IDENT "DOS"
  63. #endif
  64.  
  65.  
  66. #include "language.h"
  67.  
  68. int parse_escapes (char *);
  69.  
  70. /*
  71.  *  get_language - read in BinkleyTerm language source
  72.  *
  73.  * Read lines into table, ignoring blanks and comments
  74.  * Store into a contiguous block of memory with the individual
  75.  *     members being referenced by an array of pointers
  76.  * Store number of lines read into pointer_size
  77.  * Store amount of memory used into memory_size
  78.  *
  79.  */
  80.  
  81. int get_language (char *name_of_file)
  82. {
  83.     int             len;                        /* length of current string  */
  84.     int             count_from_file;            /* no. of strings in file    */
  85.     int             file_version;               /* version of file           */
  86.     char           *p, *q;                      /* miscellaneous pointers    */
  87.     char           *storage;                    /* where we're storing now   */
  88.     char          **load_pointers;              /* pointer to pointer array  */
  89.     char            linebuf[255];               /* biggest line we'll allow  */
  90.     FILE           *fpt;                        /* stream pointer            */
  91.     int             internal_count;             /* How many strings we got   */
  92.     int             total_size;                 /* How big it all is         */
  93.     int             error;                      /* Internal error value      */
  94.     int             PrdctCode;                  /* Product Code              */
  95.     char           *PrdctNm;
  96.     char           *PrdctPtr = PrdctMem;
  97.     char           *n;
  98.     char           *LangStart;
  99.     unsigned int    ansival;                    /* Scanned ANSI keymap value */
  100.  
  101.     internal_count = 0;                         /* zero out internal counter */
  102.     count_from_file = 0;                        /* zero out internal counter */
  103.     total_size = 0;                             /* Initialize storage size   */
  104.     error = 0;                                  /* Initialize error value    */
  105.  
  106.     load_pointers = pointers;                   /* Start at the beginning    */
  107.     storage = memory;                           /* A very good place to start*/
  108.  
  109.     /*
  110.      * Open the file now. Then read in the appropriate table. First line of
  111.      * the file contains the number of lines we want Second line through end:
  112.      * ignore if it starts with a ; and store only up to ;
  113.      *
  114.      */
  115.  
  116.     fpt = fopen (name_of_file, "r");            /* Open the file             */
  117.     if (fpt == NULL)                            /* Were we successful?       */
  118.         {
  119.         (void) fprintf (stderr, "Can not open input file %s\n", name_of_file);
  120.         return (-1);                            /* Return failure to caller  */
  121.         }
  122.  
  123.     while (fgets (linebuf, 254, fpt) != NULL)   /* read a line in            */
  124.         {
  125.         p = q = linebuf;                        /* set up for scan           */
  126.  
  127. /*
  128.  * This label is only hit when a ? line is seen.
  129.  *
  130.  * The format of a ? line is:
  131.  *
  132.  *        ?xxx ....
  133.  *
  134.  * where xxx is a 3-character platform identifier. For DOS systems,
  135.  * the identifier is DOS and for OS/2 it is OS2. The text following
  136.  * ?xxx is the same format as any other language file line.
  137.  *
  138.  * When we see a ?, we compare the following string to the ID of our
  139.  * current platform. If it matches, we point p and q at the text following
  140.  * the expression, and (I'm sorry) jump back. If it doesn't match, we throw
  141.  * the line away.
  142.  */
  143.  
  144. re_cycle:
  145.  
  146.         switch (*p)
  147.             {
  148.  
  149.             case '?':
  150.  
  151.             if (strncmp (++p, OS_IDENT, 3) == 0)
  152.                {
  153.                q = p += 3;
  154.                goto re_cycle;
  155.                }
  156.             break;
  157.  
  158.             case ';':                           /* Comment                   */
  159.             case 'C':                           /* Comment                   */
  160.  
  161.             break;
  162.  
  163.             case 'L':                           /* Language Line             */
  164.  
  165.             LangStart = ++p;
  166.             (void) parse_escapes (p);
  167.             if ((len = strlen (p)) == 0)      /* Is anything there?        */
  168.                 continue;                     /* No -- ignore.             */
  169.  
  170.             if (!count_from_file)
  171.                 {
  172.                 (void) sscanf (LangStart,"%d %d",&count_from_file, &file_version);
  173.                 if (count_from_file <= pointer_size)
  174.